package cn.xd.core.response;

import java.util.Collection;
import java.util.function.Consumer;

/**
 * @author: mirzaLin
 * @data: 2023/11/19
 * @description: Collect组合
 **/
public class OptionalCollectResult<T> {

    private final IntegerResult integerResult;

    private final CollectResult<T> collectResult;

    private OptionalCollectResult(IntegerResult integerResult, CollectResult<T> collectResult) {
        this.integerResult = integerResult;
        this.collectResult = collectResult;
    }

    public static <T> OptionalCollectResult<T> of(IntegerResult integerResult, CollectResult<T> collectResult) {
        return new OptionalCollectResult<>(integerResult, collectResult);
    }

    public void failThrow(String msg) throws RuntimeException {
        integerResult.failThrow(msg);
    }


    public void fail(Function function) {
        integerResult.fail(function);
    }

    public void failThrow() {
        integerResult.failThrow();
    }

    public void success(Function function) {
        integerResult.success(function);
    }

    public void success(Consumer<Collection<T>> consumer) {
        integerResult.success(() -> collectResult.isNotEmpty(consumer));
    }

    public Collection<T> get() {
        return collectResult.get();
    }
}
